package com.cxlin.cwanandroid.model.repository

import com.cxlin.base.model.api.BaseRepository
import com.cxlin.cwanandroid.model.bean.Banner
import com.cxlin.base.model.api.Result
import com.cxlin.cwanandroid.model.api.WanRetrofitClient
import com.cxlin.cwanandroid.model.bean.ArticleList

/**
 *
 * @Author: chenxunlin
 * @Date: 2024/4/26 15:12
 */
class HomeRepository : BaseRepository(){

    suspend fun getBanners() : Result<List<Banner>>{
        return safeApiCall(call = {requestBanners()}, errorMessage = "")
    }

    private suspend fun requestBanners(): Result<List<Banner>> =
        executeResponse(WanRetrofitClient.service.getBanner())

    suspend fun getArticleList(page: Int): Result<ArticleList> {
        return safeApiCall(call = { requestArticleList(page) }, errorMessage = "")
    }

    private suspend fun requestArticleList(page: Int): Result<ArticleList> =
        executeResponse(WanRetrofitClient.service.getHomeArticles(page))

    suspend fun collectArticle(articleId:Int): Result<ArticleList>{
        return safeApiCall(
            call = {executeResponse(WanRetrofitClient.service.collectArticle(articleId))},
            errorMessage = "网络错误"
        )
    }
    suspend fun cancelCollectArticle(articleId:Int): Result<ArticleList>{
        return safeApiCall(
            call = {executeResponse(WanRetrofitClient.service.cancelCollectArticle(articleId))},
            errorMessage = "网络错误"
        )
    }
}